Working With Printer Objects
Each job object references two printer objects, a formatting printer and an output printer. A printer object is implicitly created by theGXNewJob
function. There is no external application interface to create or dispose of printer objects.Examples of how to retrieve a printer object's properties, such as the printer name, printer type, driver name, and driver type are shown in Listing 4-1 on page 4-22. The following sections show you how to obtain the view devices associated with a printer and use them to determine a printer's resolution, color space, and color profile.
Determining a Printer's Resolution
You can determine a printer's resolution from the view devices to which the printer refers. The mapping property of the view device object contains a matrix in which the scaling information is stored. Listing 4-5 shows how to obtain the highest resolution that a printer supports.Listing 4-5 Determining a printer's resolution
void MyGetFormatDeviceResolution(gxJob whichJob, fixed *hRes, fixed *vRes) { gxPrinter formatPrinter; long numViewDevices, idx; gxViewDevice printerVDev; gxMapping vDevMapping; *hRes = 0; *vRes = 0; /* Get the formatting printer and the number of view devices for that printer. */ formatPrinter = GXGetJobFormattingPrinter(whichJob); numViewDevices = GXCountPrinterViewDevices (formatPrinter); /* Loop through the view devices that this printer supports. */ for (idx = 1; idx <= numViewDevices; idx++) { printerVDev = GXGetPrinterViewDevice(formatPrinter, idx); GXGetViewDeviceMapping(printerVDev, &vDevMapping); if ((vDevMapping.map[0][0] > *hRes) && (vDevMapping.map[1][1] > *vRes)) { *hRes = vDevMapping.map[0][0]; *vRes = vDevMapping.map[1][1]; } } /* Convert scaling factors (multiples of 72 dpi) into resolutions. */ *hRes = FixedMultiply(*hRes, ff(72)); *vRes = FixedMultiply(*vRes, ff(72)); }Retrieving the Color Profile and Color Space for a Printer
If you wish to retrieve the color profile for a printer, you can call theGXFindPrinterProfile
function to obtain the reference to a printer's color profile object, or you can call theGXFindFormatProfile
function to obtain the reference to a format's color profile object. You can set these color profiles with theGXSetPrinterProfile
andGXSetFormatProfile
functions, respectively. These functions are described in the reference section of this chapter, starting on page 4-84.If you want to obtain the color profile of a printer associated with a job object, you can obtain the printer object and, with this reference, you can obtain a reference to the printer's view device. The view device's bitmap shape points to both the color set and the color profile for the printer. Listing 4-6 shows how to retrieve the color profile and color space for the formatting printer.
Listing 4-6 Retrieving the printer's color profile and color space
gxColorProfile MyGetFormattingPrinterProfile (MyDocumentPtr myDocument, gxColorSpace *theSpace) { gxShape deviceBitMap; gxBitmap deviceBits; gxPrinter formattingPrinter; gxColorProfile theProfile; gxViewDevice printerDevice; /* Get the first profile for the formatting printer. */ formattingPrinter = GXGetJobFormattingPrinter(myDocument->documentJob); GXFindPrinterProfile(formattingPrinter, nil, 1, &theProfile); /* Look at the characteristics of the formatting printer's view device and retrieve the printer's color space. */ printerDevice = GXGetPrinterViewDevice(formattingPrinter, 0); deviceBitMap = GXGetViewDeviceBitmap(printerDevice); GXGetBitmap(deviceBitMap, &deviceBits, nil); *theSpace = deviceBits.space; GXDisposeShape(deviceBitMap); return theProfile; }Listing 4-7 shows how the printer's color profile and color space may be used to determine if a color to be printed is in gamut and to convert the color into the printer's color space.Listing 4-7 Using the printer's color profile to convert colors
Boolean MyMakePrinterColor(gxJob theJob, gxColor *sourceColor, gxColor *printedColor) { gxColorProfile printerProfile; gxColorSpace printerSpace; Boolean inGamut; /* Get the printer's profile. */ printerProfile = MyGetFormattingPrinterProfile(theJob, &printerSpace); /* Copy the source color, see if it is in gamut, and convert it into the device's color space. */ *printedColor = *sourceColor; inGamut = GXCheckColor(printedColor, printerSpace, nil, printerProfile); GXConvertColor(printedColor, printerSpace, nil, printerProfile); return inGamut; }
- Note
- For more information about colors, color profiles, and color spaces, see the color and color-related objects chapter of Inside Macintosh: QuickDraw GX Objects.
![]()
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help